package 路径总和;

public class Solution2 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if(root == null)
            return false;
        return hasPathSum1(root, targetSum - root.val);
    }
    public boolean hasPathSum1(TreeNode root, int targetSum){
        if (root.left == null && root.right == null) {
            return targetSum == 0;
        }
        if (root.left != null) {
            if(hasPathSum1(root.left, targetSum - root.left.val)) return true;
        }
        if (root.right != null) {
            if(hasPathSum1(root.right, targetSum - root.right.val)) return true;
        }
        return false;
    }
}
